package cn.maihe.elg.operation.model.dto;

import cn.maihe.elg.operation.model.enums.ResponseCodeEnum;
import lombok.Data;

/**
 * @Description
 * @Author SSX
 * @Date 2025/05/20
 */
@Data
public class BaseResponse<T> {

    private String code;
    private String message;
    private T data;

    public BaseResponse(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public BaseResponse(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public static <T> BaseResponse of(ResponseCodeEnum responseCodeEnum, T data) {
        return new BaseResponse<T>(responseCodeEnum.getRespCode(), responseCodeEnum.getRespDesc(), data);
    }

    public static BaseResponse success() {
        return new BaseResponse(ResponseCodeEnum.SUCCESS.getRespCode(), ResponseCodeEnum.SUCCESS.getRespDesc());
    }

    public static <T> BaseResponse success(T data) {
        return new BaseResponse<T>(ResponseCodeEnum.SUCCESS.getRespCode(), ResponseCodeEnum.SUCCESS.getRespDesc(), data);
    }

    public static BaseResponse error() {
        return new BaseResponse(ResponseCodeEnum.FAILURE.getRespCode(), ResponseCodeEnum.FAILURE.getRespDesc());
    }

    public static BaseResponse error(String message) {
        return new BaseResponse(ResponseCodeEnum.FAILURE.getRespCode(), message);
    }

    public static BaseResponse error(ResponseCodeEnum responseCodeEnum) {
        return new BaseResponse(responseCodeEnum.getRespCode(), responseCodeEnum.getRespDesc());
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
